package com.jiawa.wiki.Controller;

import com.jiawa.wiki.req.CategoryQueryReq;
import com.jiawa.wiki.req.CategorySaveReq;
import com.jiawa.wiki.resp.CategoryQueryResp;
import com.jiawa.wiki.resp.CommonResp;
import com.jiawa.wiki.resp.CategoryQueryResp;
import com.jiawa.wiki.resp.PageResp;
import com.jiawa.wiki.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    //依赖注入
    @Resource
    public CategoryService categoryService;
    @GetMapping("/list")
    public CommonResp<PageResp<CategoryQueryResp>> list(@Valid CategoryQueryReq req){
        PageResp<CategoryQueryResp> list = categoryService.getlist(req);
        CommonResp<PageResp<CategoryQueryResp>> resp =new CommonResp<>();
        resp.setContent(list);
        return resp;

    }

    @GetMapping("/all")
    public CommonResp all(){
        List<CategoryQueryResp> list = categoryService.all();
        CommonResp<List<CategoryQueryResp>> resp =new CommonResp<>();

        resp.setContent(list);
        return resp;

    }
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody CategorySaveReq req){
        categoryService.save(req);

        CommonResp resp =new CommonResp<>();

        return resp;
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable long id){
        categoryService.delete(id);

        CommonResp resp =new CommonResp<>();

        return resp;

}}

